/**
 * @author wyvonj
 * @date 2019-07-04
 * @description 接口
 */

import http from './config';
import Axios, { AxiosPromise, AxiosRequestConfig } from 'axios';
import { Response, SecurityPrincipalVo, AuthorityInfoVo, VerificationCodeVo, CustomUserLoginInfo, TaskInfo, ReqTaskInfo, PageVo, RespTaskInfo, ReqTaskOrder, RespTaskOrder, ReqUserInfo, RespUserInfo, ReqProfitIncome, ProfitIncome, RespProfitIncome, ShopInfo, ProfitLogRequest, ProfitLog, ReqCashAccountSetInfo, CashAccountSet } from './bean';

/**
 * 登录接口
 */

class Login {

  public static handleLogin = {
    p: 'userLogin/login',
    r: (params: SecurityPrincipalVo): AxiosPromise<Response<AuthorityInfoVo>> => {
      return http.post(`userLogin/login`, params);
    },
  };

  /**
   * 获取邀请码
   */
  public static getInvitationCode = {
    p: 'userLogin/invitationCode',
    r: (params: {
      ticket: string
    }): AxiosPromise<Response<any>> => {
      return http.post(`userLogin/invitationCode`, params);
    },
  };

  /**
   * 获取验证码
   */
  public static getAuthCode = {
    p: 'userLogin/sendEmailCode',
    r: (params: VerificationCodeVo): AxiosPromise<Response<any>> => {
      return http.post(`userLogin/sendEmailCode`, params);
    },
  };

  /**
   * 校验验证码
   */
  public static validateAuthCode = {
    p: 'userLogin/authEmailCode',
    r: (params: VerificationCodeVo): AxiosPromise<Response<any>> => {
      return http.post(`userLogin/authEmailCode`, params);
    },
  };

  /**
   * 用户注册
   */
  public static handleRegister = {
    p: 'userLogin/saveUser',
    r: (params: CustomUserLoginInfo): AxiosPromise<Response<any>> => {
      return http.post(`userLogin/saveUser`, params);
    },
  };

  /**
   * 登录名验证
   */
  public static checkLoginAccount = {
    p: 'userLogin/isLoginAccount',
    r: (params: {
      loginAccount: string,
      userType: number,
    }): AxiosPromise<Response<Boolean>> => {
      return http.get(`userLogin/isLoginAccount`, { params });
    },
  };

  public static handleLogout = {
    p: 'userLogin/quitLonin',
    r: (params: {
      ticket: string
    }): AxiosPromise<Response<any>> => {
      return http.post(`userLogin/quitLonin`, params);
    },
  };


}

class Task {

  /**
   * 发布任务
   */
  public static releaseTask = {
    p: 'task/saveTask',
    r: (params: TaskInfo): AxiosPromise<Response<any>> => {
      return http.post(`task/saveTask`, params);
    },
  };

  /**
   * 获取任务列表
   */
  public static getTaskList = {
    p: 'task/taskList',
    r: (params: ReqTaskInfo): AxiosPromise<Response<PageVo<RespTaskInfo>>> => {
      return http.post(`task/taskList`, params);
    },
  };

  public static getSingleTask = {
    p: 'task/getSingleTask',
    r: (params: ReqTaskInfo): AxiosPromise<Response<TaskInfo>> => {
      return http.post(`task/getSingleTask`, params);
    },
  };

  /**
   * 获取详情task 不含有 对应的订单信息 
   */
  public static getSingleDetailsTask = {
    p: 'task/getSingleDetailsTask',
    r: (params: {
      taskId: number
    }): AxiosPromise<Response<PageVo<RespTaskInfo>>> => {
      return http.post(`task/getSingleDetailsTask`, params);
    },
  };

  /**
   * 获取详情task含有对应的订单信息
   */
  public static getDetailsTaskContainOrder = {
    p: 'task/getDetailsTaskContainOrder',
    r: (params: {
      taskId: number
    }): AxiosPromise<Response<PageVo<RespTaskInfo>>> => {
      return http.post(`task/getDetailsTaskContainOrder`, params);
    },
  };


  /**
   * 重新发布任务
   */
  public static republish = {
    p: 'task/publish/{taskId}',
    r: (params: {
      taskId: number
    }): AxiosPromise<Response<any>> => {
      return http.post(`task/publish/${params.taskId}`, params);
    },
  };

  /**
   * 取消发布任务
   */
  public static cancelPublish = {
    p: 'task/cancelPublish/{taskId}',
    r: (params: {
      taskId: number
    }): AxiosPromise<Response<any>> => {
      return http.post(`task/cancelPublish/${params.taskId}`, params);
    },
  };

  /**
   * 完成任务
   */
  public static accomplishTask = {
    p: 'task/accomplish/{taskId}',
    r: (params: {
      taskId: number
    }): AxiosPromise<Response<any>> => {
      return http.post(`task/accomplish/${params.taskId}`, params);
    },
  };

}

class Order {
  /**
   * 订单列表
   */
  public static getOrderList = {
    p: 'taskOrder/taskOrderList',
    r: (params: ReqTaskOrder): AxiosPromise<Response<PageVo<RespTaskOrder>>> => {
      return http.post(`taskOrder/taskOrderList`, params);
    },
  };

  /**
   * 抢单接口
   */
  public static competeOrder = {
    p: 'taskOrder/saveTaskOrder/{taskId}',
    r: (params: {
      taskId: number,
    }): AxiosPromise<Response<any>> => {
      return http.post(`taskOrder/saveTaskOrder/${params.taskId}`, params);
    },
  };


  /**
   * 详情
   */
  public static getOrderDetail = {
    p: 'taskOrder/particulars/{orderId}',
    r: (params: {
      orderId: number,
    }): AxiosPromise<Response<RespTaskOrder>> => {
      return http.post(`taskOrder/particulars/${params.orderId}`, params);
    },
  };


  /**
   * 作废
   */
  public static invalidOrder = {
    p: 'taskOrder/invalid/{orderId}',
    r: (params: {
      orderId: number,
    }): AxiosPromise<Response<any>> => {
      return http.post(`taskOrder/invalid/${params.orderId}`, params);
    },
  };

  /**
   * 支付订单
   */
  public static payOrder = {
    p: 'taskOrder/payment/{orderId}',
    r: (params: {
      orderId: number,
    }): AxiosPromise<Response<any>> => {
      return http.post(`taskOrder/payment/${params.orderId}`, params);
    },
  };


  /**
   * 下订单
   */
  public static placeOrder = {
    p: 'taskOrder/savePlaceOrder',
    r: (params: any): AxiosPromise<Response<any>> => {
      return http.post(`taskOrder/savePlaceOrder`, params);
    },
  };

  /**
   * 完成订单
   */
  public static accomplishOrder = {
    p: 'taskOrder/accomplish/{orderId}',
    r: (params: {
      orderId: number,
    }): AxiosPromise<Response<any>> => {
      return http.post(`taskOrder/accomplish/${params.orderId}`, params);
    },
  };

  /**
   * 确认订单
   */
  public static confirmOrder = {
    p: 'taskOrder/notarizeOrder/{orderId}',
    r: (params: {
      orderId: number,
    }): AxiosPromise<Response<any>> => {
      return http.post(`taskOrder/notarizeOrder/${params.orderId}`, params);
    },
  };

  /**
   * 保存评价
   */
  public static saveReview = {
    p: 'taskOrder/saveEvaluate',
    r: (params: {
      orderId: number,
      img: string,
    }): AxiosPromise<Response<any>> => {
      return http.post(`taskOrder/saveEvaluate`, params);
    },
  };

  /**
   * 保存评价
   */
  public static confirmReview = {
    p: 'taskOrder/saveEvaluate',
    r: (params: {
      orderId: number,
    }): AxiosPromise<Response<any>> => {
      return http.post(`taskOrder/saveEvaluate`, params);
    },
  };

}

/**
 * 流水管理
 */
class Bill {
  public static getMyBillList = {
    p: 'pofitIncome/myBill',
    r: (params: ReqProfitIncome): AxiosPromise<Response<PageVo<ProfitIncome>>> => {
      return http.post(`pofitIncome/myBill`, params);
    },
  };

    /**
   * 流水明细列表
   */
  public static getProfitIncomeList = {
    p: 'pofitIncome/getPofitIncomeList',
    r: (params: ReqProfitIncome): AxiosPromise<Response<PageVo<RespProfitIncome>>> => {
      return http.post(`pofitIncome/getPofitIncomeList`, params);
    },
  };

  /**
   * 获取账单资金详情
   */
  public static getProfitLogList = {
    p: 'profitLog/getProfitLogList',
    r: (params: ProfitLogRequest): AxiosPromise<Response<PageVo<ProfitLog>>> => {
      return http.post(`profitLog/getProfitLogList`, params);
    },
  };

  /**
   * 保存流水 按类型 充值 提现 保存到流水列表中
   */
  public static saveBill = {
    p: 'pofitIncome/save',
    r: (params: ProfitIncome): AxiosPromise<Response<any>> => {
      return http.post(`/pofitIncome/save`, params);
    },
  };

  /**
   * 获取流水详情
   */
  public static getProfitIncomeDetails = {
    p: 'pofitIncome/getProfitIncomeParticulars/{incomeId}',
    r: (params: ProfitIncome): AxiosPromise<Response<any>> => {
      return http.post(`/pofitIncome/getProfitIncomeParticulars/${params.incomeId}`, params);
    },
  };

}


class User {
  /**
   * 买家列表
   */
  public static getUserList = {
    p: 'user/userList',
    r: (params: ReqUserInfo): AxiosPromise<Response<PageVo<RespUserInfo>>> => {
      return http.post(`/user/userList`, params);
    },
  };

  /**
   * 用户列表
   */
  public static getUserInfoList = {
    p: 'user/UserInfoList',
    r: (params: ReqUserInfo): AxiosPromise<Response<PageVo<RespUserInfo>>> => {
      return http.post(`/user/UserInfoList`, params);
    },
  };

  /**
   * 用户列表
   */
  public static getSingleUserInfo = {
    p: 'user/singleUserInfo/{userId}',
    r: (params: {
      userId: number,
    }): AxiosPromise<Response<RespUserInfo>> => {
      return http.post(`/user/singleUserInfo/${params.userId}`);
    },
  };
  /**
   * 用户余额
   */
  public static getUserBalance = {
    p: 'user/getUserBalance',
    r: (): AxiosPromise<Response<RespUserInfo>> => {
      return http.post(`/user/getUserBalance`);
    },
  };

  
  /**
   * 提现账户列表
   */
  public static getAccountList = {
    p: 'cashAccountSet/getCashAccountSetList',
    r: (params: ReqCashAccountSetInfo): AxiosPromise<Response<PageVo<CashAccountSet>>> => {
      return http.post(`/cashAccountSet/getCashAccountSetList`, params);
    },
  };

  /**
   * 保存提现账户
   */
  public static saveAccount = {
    p: 'cashAccountSet/save',
    r: (params: CashAccountSet): AxiosPromise<Response<any>> => {
      return http.post(`/cashAccountSet/save`, params);
    },
  };
}

class FileHandler {
  public static uploadFile = {
    p: 'file/upload',
    r: (params: FormData, config: AxiosRequestConfig): AxiosPromise<Response<any>> => {
      return http.post(`/file/upload`, params, config);
    },
  };
}

class Shop {
  /**
   * 获取店铺列表
   */
  public static getShopList = {
    p: 'shopInfo/getShopInfoUser',
    r: (params: any): AxiosPromise<Response<PageVo<ShopInfo>>> => {
      return http.post(`/shopInfo/getShopInfoUser`, params);
    },
  };

  /**
   * 添加店铺
   */
  public static addShop = {
    p: 'shopInfo/save',
    r: (params: ShopInfo): AxiosPromise<Response<any>> => {
      return http.post(`/shopInfo/save`, params);
    },
  };

  

  /**
   * 获取单条店铺信息
   */
  public static deleteShop = {
    p: 'shopInfo/save',
    r: (params: ShopInfo): AxiosPromise<Response<any>> => {
      return http.post(`/shopInfo/save`, params);
    },
  };


  /**
   * 删除店铺
   */
  public static getSingleShop = {
    p: 'userCenter/getShopParticulars/{shopId}',
    r: (params: ShopInfo): AxiosPromise<Response<any>> => {
      return http.post(`/userCenter/getShopParticulars/${params.shopId}`, params);
    },
  };
}

export {
  Login,
  Task,
  Order,
  Bill,
  User,
  Shop,
  FileHandler,
};